package nrrg.zhujuxing.application.learnscala

object classExtendTest {
  def main(args: Array[String]): Unit = {
    val person1 = new person()
    person1.printInfo()
    val person2 = new person(name="alice", 18)
    person2.printInfo()
    val student1 = new student(name="bob", age=19, studentNum = 201)
    student1.printInfo()

  }
  class person(){
    var name: String = _
    var age: Int = _
    println("1.父类主构造器")

    def this(name: String, age: Int){
      this()
      println("2.父类辅助构造器")
      this.name = name
      this.age = age
    }

    def printInfo(): Unit ={
      println(s"person ${this.name} ${this.age}")
    }
  }

  class student() extends person{
    var studentNum: Int = _
    println("3.子类主构造器")

    def this(name: String, age: Int, studentNum: Int){
      this()
      println("4.子类辅助构造器")
      this.name = name
      this.age = age
      this.studentNum = studentNum
    }

    override def printInfo(): Unit = {
      println(s"student ${this.name} ${this.age} ${this.studentNum}")
    }
  }
}
